package com.g7.dsp;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;

import com.g7.dsp.forprotocol.contexts.ApplicationContext;
import com.g7.dsp.forprotocol.ui.CtBoxGui;
import com.g7.dsp.forprotocol.ui.SmartGui;
import com.g7.dsp.forprotocol.ui.integrated.Window;
import com.g7.dsp.fortest.ui.ConvertGui;

public class MainEntrance implements ActionListener{
	JFrame jFrame;
	ImageIcon imgIcon;
	JMenuBar menuBar;
	JMenu menu1;
	JMenu menu2;
	JMenu menu3;
	JMenuItem menu1_item1;
	JMenuItem menu1_item2;
	JMenuItem menu1_item3;
	JMenuItem menu2_item1;
	JMenuItem menu3_item1;
	//集成swt报文发送工具
	Window window;
	//应用上下文
	ApplicationContext app;
	MainEntrance() {
		app = ApplicationContext.getApplicationContext();
		String frameIconPath = app.getImgDirPath()+"//g7.png";
		imgIcon = new ImageIcon(frameIconPath);
		this.jFrame = new JFrame("DSPToolS");
		this.jFrame.setIconImage(imgIcon.getImage());
		this.jFrame.setSize(400, 400);
		this.jFrame.setDefaultCloseOperation(jFrame.EXIT_ON_CLOSE);// 设置关闭退出
		this.jFrame.setBackground(Color.green);
		this.menuBar = new JMenuBar();
		this.jFrame.setJMenuBar(menuBar);
		this.menu1 = new JMenu("协议提取");
		this.menu2 = new JMenu("用例转换");
		this.menu3 = new JMenu("报文发送");
		menu1_item1 = new JMenuItem("Smart");
		menu1_item1.addActionListener(this);
		menu1_item2 = new JMenuItem("部标");
		menu1_item2.addActionListener(this);
		menu1_item3 = new JMenuItem("CTBox");
		menu1_item3.addActionListener(this);
		menu2_item1 = new JMenuItem("TestLink用例转换");
		menu2_item1.addActionListener(this);
		menu3_item1 = new JMenuItem("Smart报文");
		menu3_item1.addActionListener(this);
		this.menu1.add(menu1_item1);
		this.menu1.add(menu1_item2);
		this.menu1.add(menu1_item3);
		this.menu2.add(menu2_item1);
		this.menu3.add(menu3_item1);
		this.menuBar.add(menu1);
		this.menuBar.add(menu2);
		this.menuBar.add(menu3);
		new SmartGui(jFrame);
		this.jFrame.setVisible(true);
	}

	public static void main(String[] args) {
		System.out.println();
		new MainEntrance();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource()==menu1_item1){
			new SmartGui(jFrame);
		}else if(e.getSource()==menu1_item2){
			System.out.println("menu1_item2");
		}else if(e.getSource()==menu1_item3){
			new CtBoxGui(jFrame);
		}else if(e.getSource()==menu2_item1){
			new ConvertGui(jFrame);
		}else if(e.getSource()==menu3_item1){
			System.out.println("menu3_item1");
		    SwingUtilities.invokeLater(new Runnable() {
	            public void run() {
	                window = new Window(jFrame);
	            }
	        });
		}
	}
}
